package financial.sharing.center.system.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import financial.sharing.center.common.enums.ResponseContext;
import financial.sharing.center.common.utils.PageSize;
import financial.sharing.center.common.utils.R;
import financial.sharing.center.system.model.entity.CompanyAccount;
import financial.sharing.center.system.service.CompanyAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName CompanyAccountController
 * @Description TODO
 * @Author guoyuhang
 * @ @csdn https://blog.csdn.net/qq_40788718
 * @Date 2021/5/7
 * @Version 1.0
 */
@RestController
@RequestMapping(value = "/system/company/account/")
public class CompanyAccountController {

    @Autowired
    private CompanyAccountService companyAccountServiceImpl;

    @PostMapping(value = "get/all/company/account")
    public R getAllCompanyAccount(String selectCompanyName,
                                  Integer currentPage){
        PageHelper.startPage(currentPage, PageSize.PAGESIZE_TEN);
        PageInfo<CompanyAccount> result = this.companyAccountServiceImpl.getAllCompanyAccount(selectCompanyName);
        return R.ok(result);
    }

    @PostMapping(value = "create/one/company/account")
    public R createOneCompanyAccount(String companyName,
                                     String invoiceTaxNumber,
                                     String invoiceAddress,
                                     String invoicePhone,
                                     String invoiceDepositBank,
                                     String invoiceBankAccount){
        Integer result = this.companyAccountServiceImpl.createOneCompanyAccount(
                companyName,invoiceTaxNumber,invoiceAddress,invoicePhone,
                invoiceDepositBank,invoiceBankAccount
        );
        return R.ok(ResponseContext.int2Enum(result).getName());
    }

    @PostMapping(value = "compile/one/company/account")
    public R compileOneCompanyAccount(@RequestBody CompanyAccount companyAccount){
        Integer result = this.companyAccountServiceImpl.compileOneCompanyAccount(companyAccount);
        return R.ok(ResponseContext.int2Enum(result).getName());
    }

    @PostMapping(value = "delete/one/company/account")
    public R deleteOneCompanyAccount(Integer id){
        Integer result = this.companyAccountServiceImpl.deleteOneCompanyAccount(id);
        return R.ok(ResponseContext.int2Enum(result).getName());
    }

    @PostMapping(value = "get/list/company/account")
    public R getListCompanyAccount(){
        List<CompanyAccount> result = this.companyAccountServiceImpl.getListCompanyAccount();
        return R.ok(result);
    }
}
